package com.oocl.scheduled;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.oocl.entity.Orders;
import com.oocl.service.OrdersService;
import com.oocl.util.DateUtil;

@Component
public class AutoValidateScheduled {
	
	@Autowired
	@Qualifier("ordersService")
	private OrdersService orderService;
	
	@Value("#{configProperties['shceduled.interval']}")
	private String validateTime;
	
	public AutoValidateScheduled(){
		System.out.println("init autoavalidateScheduled...");
	}

	@Scheduled(fixedDelay = 2000)
	public void work(){
		
//		System.out.println("do interval task.... ");
		
		
		List<Orders> orders = orderService.getByStatus("3");
		for(Orders order : orders){
//			System.out.println("task.... change" + order.getId() + "has auto valid");
			if(DateUtil.getTimeDelta(new Date(), order.getOtime()) > Integer.parseInt(validateTime)){
				order.setOstate("4");
				orderService.update(order);
			}
		}
	}
	
}
